<?php
/**
 * Author Yulin
 * Func   尝试：用户中心关于用户的数据用一个js来实现。
 */
defined('IN_YuLin') || exit('NO PERMIT!');

UserLogin();
$res          = array(
    'status'  => 'error',
    'msg'     => '请求错误',
);
$operation    = $_POST['operation'];

switch ($operation){
    case 'msg':
        $tab         = Table('article');
        $whe         = ' WHERE cid = 1 AND status = 1';// 很抱歉，写死的
        $sql         = 'SELECT id, cid, title, thumb, keyword, description, content, viewnum, status, lotteryid, dateline FROM ' . $tab . $whe;
        $articleList = $db->getall($sql);
        $articleIdKey= array();
        if ($articleList){
            foreach ($articleList as $k => $v){
                $v['dateline_format'] = date('Y-m-d H:i:s', $v['dateline']);
                $articleIdKey[$v['id']] = $v;
            }
        }
        $messTab     = Table('user_message');
        $messWhe     = ' WHERE uid = ' . $_uid . ' AND status != 2 ORDER BY dateline DESC';
        $messSql     = 'SELECT id, uid, fuid, title, content, status, dateline FROM ' . $messTab . $messWhe;
        $messList    = $db->getall($messSql);
        $messIdKey   = array();
        if ($messList){
            foreach ($messList as $mk => $mv){
                $mv['dateline_format'] = date('Y-m-d H:i:s', $mv['dateline']);
                $messIdKey[$mv['id']]  = $mv;
            }
        }
        $res['status']            = 'success';
        $res['msg']               = '请求成功';
        $res['list']['article']   = $articleIdKey;
        $res['list']['msgList']   = $messIdKey;
        break;
}

echo json_encode($res);